package share

import "oc_saas/internal/model/base"

// 规则类型
const (
	MENU = "MENU" //菜单类型
	REQ  = "REQ"  //请求类型
)

// 规则权限表
type Rule struct {
	base.IDColumn
	base.SortColumn
	PID      uint    `json:"pid"`
	Name     string  `json:"name" gorm:"column:name;type:varchar(10);size:10;default:'';not null" validate:"min=2,max=10,required"`
	Perms    string  `json:"perms" gorm:"type:varchar(20);uniqueIndex;default:'';not null;comment:规则标识" validate:"ocPerms,required"`
	Link     string  `json:"-" gorm:"column:link;not null;type:varchar(255);size:255;index;comment:父子元素链条(,a,b,c,)"`
	Type     string  `json:"type" gorm:"type:varchar(10)" validate:"required,oneof=MENU REQ"`
	Route    *Route  `json:"route,omitempty" gorm:"foreignKey:RuleID;reference:ID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE"`
	Api      *Api    `json:"api,omitempty" gorm:"foreignKey:RuleID;reference:ID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE"`
	Children []*Rule `json:"children,omitempty" gorm:"foreignKey:PID;reference:ID;constraint:OnDelete:CASCADE"`
}
